package com.example.fufudamowang.listview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;



public class MainActivity extends AppCompatActivity {
    private String[] weekStrings=new String[]{"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};


    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        ArrayAdapter<String> adapter = new ArrayAdapter<String> (    //是data和ListView的桥梁，起一个适配作用
                MainActivity.this, android.R.layout.simple_list_item_1, weekStrings
        );
        ListView listView = (ListView) findViewById ( R.id.lv );
        listView.setAdapter ( adapter );
        listView.setOnItemClickListener ( new AdapterView.OnItemClickListener () {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                MainActivity.this.setTitle(((TextView) view). getText());
            }
        } );


    }
}
